﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UniversityStudentManagemnetSystem.BLL;
using UniversityStudentManagemnetSystem.DAO.DAL;

namespace UniversityStudentManagemnetSystem.UI
{
    public partial class VCPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Account/Login.aspx", false);
            }

        }

        protected void uploadButton_Click(object sender, EventArgs e)
        {
            try
            {
                Vc aVc = new Vc();
                DateTime joinDate = DateTime.Today;
                aVc.Name = nameTextBox.Text;
                aVc.Designation = designationTextBox.Text;
                aVc.PresentAddress = presentAddressTextBox.Text;
                aVc.Permanentaddress = permanentAddressTextBox.Text;
                aVc.Email = emailTextBox.Text;
                aVc.ContactNo = contactNoTextBox.Text;
                if (joiningDateTextBox.Text == "")
                {
                    joiningDateTextBox.Text = joinDate.ToString();
                }
                aVc.JoiningDate = Convert.ToDateTime(joiningDateTextBox.Text);
                VCManager manager = new VCManager();
                string message = manager.SaveVcInformation(aVc);
                messagelabel.ForeColor = Color.BlueViolet;
                messagelabel.Text = message;
                ClearTextBoxes();

            }
            catch (FormatException exception)
            {
                messagelabel.ForeColor = Color.Red;
                messagelabel.Text = exception.Message;
            }
            catch (Exception exception)
            {

                messagelabel.ForeColor = Color.Red;
                messagelabel.Text = exception.Message;
            }
          
        }

        private void ClearTextBoxes()
        {
            nameTextBox.Text = string.Empty;
            designationTextBox.Text = string.Empty;
            presentAddressTextBox.Text = string.Empty;
            permanentAddressTextBox.Text = string.Empty;
            emailTextBox.Text = string.Empty;
            contactNoTextBox.Text = string.Empty;
            joiningDateTextBox.Text = string.Empty;
        }
    }
}